package com.tedu.ivos.dict.service.impl;

import com.tedu.ivos.dict.mapper.DictMapper;
import com.tedu.ivos.dict.pojo.dto.DictQuery;
import com.tedu.ivos.dict.pojo.dto.DictSaveParam;
import com.tedu.ivos.dict.pojo.entity.Dict;
import com.tedu.ivos.dict.pojo.vo.DictVO;
import com.tedu.ivos.dict.service.DictService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Service
@Slf4j
public class DictServiceImpl implements DictService {

    @Autowired
    DictMapper dictMapper;
    @Override
    public List<DictVO> selectDict(DictQuery dictQuery) {
        log.debug("查询字典业务，参数：{}", dictQuery);
        List<DictVO> list=dictMapper.selectDict(dictQuery);
        return list;
    }

    @Override
    public void saveDict(DictSaveParam dictSaveParam) {
        // 通过id 判断是否新增还是修改
        Dict dict=new Dict();
        BeanUtils.copyProperties(dictSaveParam,dict);
        if (dict.getId()==null){
            log.debug("新增");
            dict.setCreateTime(new Date());
            dictMapper.insertDict(dict);
        }else {
            log.debug("修改");
            dict.setUpdateTime(new Date());
            dictMapper.updateDict(dict);
        }

    }

    @Override
    public void deleteDict(Long id) {
        log.debug("删除业务，参数：{}",id);
        dictMapper.deleteDict(id);
    }
}
